/*
    13. Write a C program to remove all instances of a given value in a given 
    array of integers and return the length of the new array.
    Expected Output:

    Original array: 1 1 2 3 4 4 5 6 6 6 
    Size of the new array after removing the value 4: 8
*/
#include <stdio.h>

void printArray(int a[], int len){
    int i;
    for(i = 0; i < len; i++){
        printf("%d ", a[i]);
    }
    printf("\n");
}

int removeValue(int a[], int len, int val){
    int i, j;
    for(i = 0, j = 0; i < len; i++){
        if(a[i] != val){
            a[j++] = a[i];
        }
    }
    return j;
}

int main(void){
    int a[] = {1,1,2,3,4,4,5,6,6,6};
    int len = sizeof(a) / sizeof(int);
    int val = 4;
    printf("Original array : ");
    printArray(a, len);
    int newlen = removeValue(a, len, val);    
    
    printf("Size of the new array after removing the value %d: %d\n", val, newlen);
    printf("New array : ");
    printArray(a, newlen);

    return 0;
}